#!/bin/bash
set -o errexit
# apt install net-tools

apt update -y
apt install postgresql-%VERSION% -y

systemctl enable postgresql

# ssh root@127.0.0.1
# ssh root@10.159.161.178
# scp init_postgresql.sh root@10.159.161.178:/opt/
# cat /home/fhj/code/common/db_pg/pg_hba.conf   > /etc/postgresql/%VERSION%/main/pg_hba.conf
# cat /home/fhj/code/common/db_pg/postgresql.conf > /etc/postgresql/%VERSION%/main/postgresql.conf
# systemctl status postgresql;
# systemctl stop postgresql;
# systemctl start postgresql;


# 全局查找pg配置文件的位置
# find / -name "pg_hba.conf"
# find / -name "postgresql.conf"

# 修改postgres密码的sql
# alter user postgres with  password 'qw123666';

# psql -h 127.0.0.1 -U postgres -d postgres -p 5432
# /*******************************************************************************
#    Drop database if it exists
# ********************************************************************************/
# DROP DATABASE IF EXISTS test2;


# /*******************************************************************************
#    Create database
# ********************************************************************************/
# CREATE DATABASE test2;


#备份数据
# pg_dump -h 127.0.0.1 -U postgres test2 > /var/test2.bak

# 恢复命令
# psql -h 127.0.0.1 -U postgres -d test2 < /var/test2.bak
